<?php

/**
 * 
 * @author yuxun
 *
 */
class ReplyTemplateController extends AdminBaseController {
	
	public function index(){
		$this->setTitle('回复模板列表');
	
		$filter = new PubFilter();
		$grid   = new PubGrid();
	
		$filter->addFilter('name', 'input', '名称');
	
		$params = $filter->get();
		$header = ReplyTemplateService::indexHeader();
		$data   = ReplyTemplateService::indexData($params);
	
		$grid->addGrid($header, $data);
	
		$this->out['filter'] = $filter->show();
		$this->out['grid'] = $grid->show();
	}
	

	
	public function add(){
		$this->setTitle('添加');

	}
	
	public function doAdd(){
		$result = ReplyTemplateService::doAdd($_POST);
			
		if($result['state']){
			$this->showMessage('添加成功', PubFunc::buildUrl('/oss/?r=replyTemplate/index'));
		}else{
			$this->showMessage($result['msg']);
		}
	}
	
	public function edit(){
		$id = $this->R('id');
		$info = ReplyTemplateService::get($id);
		
		if(empty($info)) $this->showMessage('找不到该信息');
	
		$this->setTitle('编辑回复模板 ：', $info['name']);

		$this->out['info'] = $info;
	}
	
	public function doEdit(){
		$id = $this->R('id');
		$result = ReplyTemplateService::doEdit($id, $_POST);
	
		if($result['state'] !== false){
			$this->showMessage('编辑成功', PubFunc::buildUrl("/oss/?r=replyTemplate/index"));
		}else{
			$this->showMessage('编辑失败');
		}
	}
	
	public function delete(){
		$id = $this->R('id');
	
		$result = ReplyTemplateService::delete($id);
	
		if($result !== false){
			$this->showMessage('删除成功', PubFunc::buildUrl("/oss/?r=replyTemplate/index"));
		}else{
			$this->showMessage('删除失败');
		}
	}
	
	public function getInfo(){
		$id = $this->R('id');
		$out = ReplyTemplateService::getInfo($id);
		$this->out = $out;
		$this->outType = 'json';
	}
	
}